//
//  HNCleanProblemView.m
//  XDEducation
//
//  Created by 星道 on 17/5/18.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNCleanProblemView.h"
#import "HNKnowledgeModel.h"
@implementation HNCleanProblemView
{
    IBOutlet UILabel *_Title;
    IBOutlet UITableView *_TableView;
    
    NSArray *_DataArr;
    BOOL _IsTeacher;
    
    void(^_SelectRow)(NSInteger,NSString *);
}



- (instancetype)initWithDataArr:(NSArray *)DataArr IsTeacher:(BOOL)IsTeacher SelectRow:(void(^)(NSInteger,NSString *))SelectRow
{
    self = [[[NSBundle mainBundle] loadNibNamed:[HNCleanProblemView description] owner:nil options:nil] lastObject];
    if (self)
    {
        _DataArr = DataArr;
        _IsTeacher = IsTeacher;
        _SelectRow = SelectRow;
        _TableView.tableFooterView = [UIView new];
        _TableView.tableHeaderView = [UIView new];
        _TableView.delegate = self;
        _TableView.dataSource = self;
    }
    return self;
}






- (IBAction)ClickButton:(UIButton *)sender
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}




#pragma TableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _DataArr.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (Cell == nil)
    {
        Cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"Cell"];
    }

        HNKnowledgeModel *Model = _DataArr[indexPath.row];
    if (_IsTeacher)
    {
        if (Model.schoolName.length > 0)
        {
            Cell.textLabel.text = [NSString stringWithFormat:@"老师代码%@-%@-%@",[Model.uid stringValue],Model.schoolName,Model.realName];
        }
        else
        {
            Cell.textLabel.text = [NSString stringWithFormat:@"老师代码%@-%@",[Model.uid stringValue],Model.realName];
        }
    }
    else
    {
        Cell.textLabel.text = Model.knowledgeName;
    }
    return Cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *Cell = [tableView cellForRowAtIndexPath:indexPath];
    if (_SelectRow)
    {
        _SelectRow (indexPath.row,Cell.textLabel.text);
    }
}
@end
